<?php $this->pageTitle = 'Templates'; ?>
<?php $this->renderPartial('_tabs'); ?>
<div class="grid_16">
	<div>
		<a id="btnAddTemplates" class="blue link" href="<?php echo $this->createUrl('templates/create'); ?>">
			<img class="valign-middle" src="/images/icons/fugue/plus-button.png" />
			New Template
		</a>
	</div>
	<br/>
	<?php
	$this->widget('PsGridView', array(
		'id' => 'templates-grid',
		'dataProvider' => $dataProvider,
		'template' => '{items}{pager}{pagesize}',
		'pagesizeCssClass' => 'pager-pagesize',
		'itemsCssClass' => 'items clear',
		'selectableRows' => 0,
		'columns' => array(
			array(
				'header' => 'Date',
				'name' => 'create_time',
				'value' => '(empty($data->create_time) ? "-" : date("j M Y", strtotime($data->create_time)))',
				'filter' => false,
				'htmlOptions' => array(
					'width' => 100,
					'class' => 'date-column'
				),
			),
			array(
				'name' => 'name',
				'htmlOptions' => array(
					'width' => '*',
					'class' => 'name-column'
				),
			),
			array(
				'name' => 'type',
				'htmlOptions' => array(
					'width' => 120,
					'class' => 'type-column'
				),
			),
			array(
				'header' => 'Agency',
				'name' => 'agencyName',
				'type' => 'raw',
				'value' => '$data->ownerParty->getAgency()->name',
				'filter' => false,
				'headerHtmlOptions' => array('width' => 120),
				'htmlOptions' => array('class' => 'agency-column no-wrap'),
				'visible' => Yii::app()->user->hasMultipleAgenciesSelected()
			),
			array(
				'header' => 'Actions',
				'class' => 'common.widgets.grid.PsActionColumn', // protected/components/PsActionColumn.php
				'htmlOptions' => array(
					'width' => 120,
					'class' => 'action-column'
				),
				'options' => array(
					'width' => 180,
				),
				'actions' => array(
					'edit' => array(
						'label' => 'Edit Template',
						'icon' => '/images/icons/fugue/pencil.png',
						'class' => 'templates-action-open',
						'url' => array('templates/update', 'id' => '$data->id'),
					),
					'delete' => array(
						'label' => 'Delete',
						'icon' => '/images/icons/fugue/cross-circle.png',
						'class' => 'templates-action-delete',
						'url' => array('templates/delete', 'id' => '$data->id'),
						'onClick' => 'js:modules.admin.templates.index.onActionDeleteClick'
					)
				)
			),
		),
	));
	?>
</div>
<div id="addTemplatesDialog" style="display: none;" title="New Template">
	<?php
	$form = $this->beginWidget('PsActiveForm', array(
		'id' => 'addTemplates-form',
		'action' => array('templates/create', 'id' => $propertyCase->id),
		'enableAjaxValidation' => false,
		'enableClientValidation' => true,
		'clientOptions' => array(
			'inputContainer' => 'tr',
			'validationDelay' => 0,
			'validateOnSubmit' => true,
		),
		'htmlOptions' => array(
			'target' => '_blank'
			)));
	?>
    <div>
		<table class="table">
			<tr>
				<td>
					<?php echo $form->labelEx($template, 'name'); ?>
				</td>
				<td>
					<?php echo $form->textField($template, 'name'); ?>
					<?php echo $form->error($template, 'name'); ?>
				</td>
			</tr>
			<tr>
				<td>
					<?php echo $form->labelEx($template, 'type'); ?>
				</td>
				<td>
					<?php
					echo $form->dropDownList($template, 'type', array(
						'Floorplan' => 'Floorplan',
						'Factsheet' => 'Factsheet'
					));
					?>
					<?php echo $form->error($template, 'type'); ?>
				</td>
			</tr>
		</table>
	</div>
	<?php $this->endWidget(); ?>
</div>